<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../lib/bootstrap-3.3.5-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/index.css">
    <link rel="stylesheet" href="../css/mall.css">
    <link rel="stylesheet" href="../css/zx.css">
    <link rel="stylesheet" href="../font/iconfont.css">
    <script src="../lib/bootstrap-3.3.5-dist/js/jquery-1.11.3.js"></script>
    <script src="../lib/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>

</head>
<style>
    .btn:disabled {
        background-color: grey;
    }

    select #city {
        display: none;
    }

    select#country {
        display: none;
    }
</style>

<body>
    <div class="kong11"></div>
    <div id="mulu">
        <!-- 导航 -->
        <div id="cateHead">
            <p><span>首页 / 商城系统 / </span>运费模板</p>
            <p>运费模板</p>
        </div>
    </div>

    <div id="catemain">
        <div id="tdheight">
            <div class="catetablehead">
                <span class="yfmb">运费模板</span>
                <button class="myxzbutn">+ 添加模板</button>
            </div>
            <div class="mb mb1">
                <div>
                    <span>圆通运费模板</span>
                    <span>最近编辑时间:2019-04-11 15:36</span>
                    <div class="aright">
                        <button>复制模板</button>
                        <button>修改</button>
                        <button class="del1">删除</button>
                    </div>

                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>物流公司</th>
                            <th>运送到</th>
                            <th>商品≤1kg</th>
                            <th>1kg< 商品≤2kg </th>
                            <th>2kg< 商品≤3kg</th>
                            <th>每增加1kg，增加运费</th>
                        </tr>
                    </thead>
                    <tbody id="mytbodymb1">
                    </tbody>
                </table>
            </div>
            <div class="mb mb2">
                <div>
                    <span>中通运费模板</span>
                    <span>最近编辑时间:2019-04-11 15:36</span>
                    <div class="aright">
                        <button>复制模板</button>
                        <button>修改</button>
                        <button class="del2">删除</button>
                    </div>

                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>物流公司</th>
                            <th>运送到</th>
                            <th>商品≤10m3</th>
                            <th>每增加m3，增加运费</th>

                        </tr>
                    </thead>
                    <tbody id="mytbodymb2">
                    </tbody>
                </table>
            </div>
            <div class="mb mb3">
                <div>
                    <span>顺丰运费模板</span>
                    <span>最近编辑时间:2019-04-11 15:36</span>
                    <div class="aright">
                        <button>复制模板</button>
                        <button>修改</button>
                        <button class="del3">删除</button>
                    </div>

                </div>
                <table class="table">
                    <thead>
                        <tr>
                            <th>物流公司</th>
                            <th>运送到</th>
                            <th>件数≤10</th>
                            <th>每增加1件，增加运费</th>
                        </tr>
                    </thead>
                    <tbody id="mytbodymb3">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div id="xzmoban">
        <table>
            <tr>
                <td>模板名称</td>
                <td><input type="text" class="grayborder"></td>
            </tr>
            <tr>
                <td>商品地址</td>
                <td>您选择的是： <input type="text" value="" id="addr-show" class="grayborder txtwidsaml">

                    <!-- 省份选择 -->
                    <select id="prov" name="prov" onchange="showCity(this)" class="mobandqselect">
                        <option>请选择省份</option>
                    </select>
                    <!-- 城市选择 -->
                    <select id="city" onchange="showCountry(this)" class="mobandqselect">
                        <option>请选择城市</option>
                    </select>
                    <!-- 区县选择 -->
                    <select id="country" onchange="selectCountry(this)" class="mobandqselect">
                        <option>请选择县区</option>
                    </select>

                    <button type="button" class="btn" onClick="showAddr()">确定</button>

                </td>
            </tr>
            <tr>
                <td>运费承担</td>
                <td><input type="radio" name="mj" id="mj1">买家承担运费<input type="radio" name="mj" id="mj2">卖家承担运费</td>
            </tr>
            <tr>
                <td>计价方式</td>
                <td><input type="radio" name="ja" id="zl" value="按重量">按重量<input type="radio" name="ja" id="tj"
                        value="按体积">按体积<input type="radio" name="ja" id="js" value="按件数">按件数</td>
            </tr>
            <tr>
                <td>快递公司

                </td>
                <td> <select name="" id="" class="mobandqselect">
                        <option>圆通快递</option>
                        <option>中通快递</option>
                        <option>顺丰快递</option>
                    </select></td>
            </tr>
            <tr>
                <td>计费规则</td>
                <td></td>
            </tr>
        </table>
        <table id='zlmoban' class="table">
            <thead>
                <th>运送到</th>
                <th>首重量</th>
                <th>首费</th>
                <th>续重量</th>
                <th>续费</th>
            </thead>
            <tbody id="zlmobanbody"></tbody>
        </table>
        <table id='jsmoban' class="table">
            <thead>
                <th>运送到</th>
                <th>首重量</th>
                <th>首费</th>
                <th>续重量</th>
                <th>续费</th>
            </thead>
            <tbody id="jsmobanbody"></tbody>
        </table>
        <table id='tjmoban' class="table">
            <thead>
                <th>运送到</th>
                <th>首重量</th>
                <th>首费</th>
                <th>续重量</th>
                <th>续费</th>
            </thead>
            <tbody id="tjmobanbody"></tbody>
        </table>
    </div>

    <div>
        <span class="foot1">大健康综合管理后台</span>
        <span class="foot2">版权所有:@大健康综合(集团)有限公司Meinian Onehealth Healthcare (Group)Co.</span>
        <span class="foot2">沪ICP备09017846号-3沪公网安备31010602006448号</span>
    </div>
    <script src="../JavaScript/index.js"></script>
    <script src="../JavaScript/data.js"></script>
    <script src="../JavaScript/utils.js"></script>
    <script src="../JavaScript/mall.js"></script>
    <script>
        function showcostdata() {
            YTData.forEach(item => {
                $('#mytbodymb1').append(`
                <tr>
                            <td>${item.company}</td>
                            <td>${item.place}</td>
                            <td>${item.onekg}</td>
                            <td>${item.twokg}</td>
                            <td>${item.threekg}</td>
                            <td>${item.addkg}</td>
                        </tr>
                `)
            });
            ZTData.forEach(item => {
                $('#mytbodymb2').append(`
                <tr>
                            <td>${item.company}</td>
                            <td>${item.place}</td>
                            <td>${item.tenjs}</td>
                            <td>${item.addjs}</td>
                        </tr>
                `)
            });
            SFData.forEach(item => {
                $('#mytbodymb3').append(`
                <tr>
                            <td>${item.company}</td>
                            <td>${item.place}</td>
                            <td>${item.tenlf}</td>
                            <td>${item.addlf}</td>
                        </tr>
                `)
            });

        }
        showcostdata()
        $('.del1').click(function () {
            $('.mb1').remove()

        })
        $('.del2').click(function () {
            $('.mb2').remove()

        })
        $('.del3').click(function () {
            $('.mb3').remove()

        })

        $('.myxzbutn').click(function () {
            $('#mulu #cateHead').css({
                display: 'none'
            })
            $('#mulu').append(`<div id="cateHead">
                            <p><span>首页 / 商城系统 /运费模板 / </span>添加运费模板</p>
                            <p>添加运费模板</p>
                        </div>`)
            $('#tdheight').css({
                display: 'none'
            })
            $('#xzmoban').css({
                display: 'block'
            })

        })
        // 单选按钮
        $("input[type='radio']").each(function () {
            var id = $(this).attr("id");
            // 判断是单选按钮是否选择
            // $(this).is(":checked")
            if ($("#" + id).attr("checked") == "checked") {
                var fs = $("#" + id).val();
            }
        });
        var s1 = $(".aa:checked").val(); // .aa 为class
        var s2 = $("input[name='ra']:checked").val();

        $(function () {
            $("input[type='radio']").click(function () {
                var id = $(this).attr("id");
                if (id == 'zl') {
                    $('#zlmobanbody tr').remove()
                    $('#jsmobanbody tr').remove()
                    $('#tjmobanbody tr').remove()
                    mycatexzarrylab = []
                    kdaddress(YTData)
                    console.log(mycatexzarrylab);
                    myxztable(5, 5, '#zlmobanbody', mycatexzarrylab, '#zlmoban')
                };
                if (id == 'js') {
                    $('#zlmobanbody tr').remove()
                    $('#jsmobanbody tr').remove()
                    $('#tjmobanbody tr').remove()
                    mycatexzarrylab = []
                    kdaddress(ZTData)
                    console.log(mycatexzarrylab);
                    myxztable(5, 5, '#jsmobanbody', mycatexzarrylab, '#jsmoban')
                };
                if (id == 'tj') {
                    $('#zlmobanbody tr').remove()
                    $('#jsmobanbody tr').remove()
                    $('#tjmobanbody tr').remove()
                    mycatexzarrylab = []
                    kdaddress(SFData)
                    console.log(mycatexzarrylab);
                    myxztable(5, 5, '#tjmobanbody', mycatexzarrylab, '#tjmoban')
                };
            });
        })
        // 获取快递地址
        var mycatexzarrylab = []
        function kdaddress(arr) {
            arr.forEach(item => {
                mycatexzarrylab.push(item.place)
            });


        }
        // 用来生成table框架
        function myxztable(mytr, mytd, wz, mycatexzarrylab, moban) {
            $(moban).css({
                display: 'block'
            })
            $(`#xzmoban .table:not(${moban})`).css({
                display: 'none'
            })
            for (let m = 0; m < mytr; m++) {

                $(wz).append(`<tr class="myxztr"></tr>`)
                $(`.myxztr:nth-of-type(${m + 1})`).append(`<td>${mycatexzarrylab[m]}</td>`)
                for (let n = 0; n < mytd; n++) {
                    $(`.myxztr:nth-of-type(${m + 1})`).append(`<td><input type="text" class="grayborder txtwidzx" placeholder=""></td>`)

                }
            }
        }
        $(function () {
            var current_prov;
            var current_city;
            var current_country;
            /* 自动加载省份列表 */
            showPro();
        });
        function showPro() {
            $(".btn").disabled = true;
            var len = province.length;
            for (var i = 0; i < len; i++) {
                var provOpt = document.createElement("option");
                provOpt.innerText = province[i]['name'];
                provOpt.value = i;
                prov.appendChild(provOpt);
            }
        };
        /*根据所选的省份来显示城市列表*/
        function showCity(obj) {
            var val = obj.options[obj.selectedIndex].value;
            current_prov = val;
            if (val >= 0) {
                city.style.display = 'inline-block';
                country.style.display = 'none';
            } else {
                city.style.display = 'none';
                country.style.display = 'none';
            }
            if (val != null) {
                city.length = 1;
                if (province[val]) {
                    var cityLen = province[val]["city"].length;
                }
                for (var j = 0; j < cityLen; j++) {
                    var cityOpt = document.createElement('option');
                    cityOpt.innerText = province[val]["city"][j].name;
                    cityOpt.value = j;
                    city.appendChild(cityOpt);
                }
            }
        };
        /*根据所选的城市来显示县区列表*/
        function showCountry(obj) {
            var val = obj.options[obj.selectedIndex].value;
            if (val >= 0) {
                country.style.display = 'inline-block';
            } else {
                country.style.display = 'none';
            }
            current_city = val;
            if (val != null) {
                country.length = 1;
                if (province[current_prov]["city"][val]) {
                    var countryLen = province[current_prov]["city"][val].districtAndCounty.length;
                }
                if (countryLen == 0) {
                    addrShow.value = province[current_prov].name + '-' + province[current_prov]["city"][val].name;
                    return;
                }
                for (var n = 0; n < countryLen; n++) {
                    var countryOpt = document.createElement('option');
                    countryOpt.innerText = province[current_prov]["city"][val].districtAndCounty[n];
                    countryOpt.value = n;
                    country.appendChild(countryOpt);
                }
            }
        };

        function selectCountry(obj) {
            current_country = obj.options[obj.selectedIndex].value;
            $(".btn").disabled = false;

        };
        function showAddr() {
            var ss = province[current_prov].name + "|" +
                province[current_prov]['city'][current_city].name + "|" +
                province[current_prov]['city'][current_city]['districtAndCounty'][current_country];
            $("#addr-show").val(ss);
        }




    </script>
</body>

</html>